package com.fw.web.controller.system;

import java.util.List;

import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.fw.annotation.Log;
import com.fw.core.controller.BaseController;
import com.fw.core.domain.AjaxResult;
import com.fw.enums.BusinessType;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import javax.validation.Valid;
import static com.fw.mes.ResultUtils.success;
import com.fw.system.admin.domain.TbSysRule;
import com.fw.system.admin.service.ITbSysRuleService;
import com.fw.utils.poi.ExcelUtil;
import lombok.RequiredArgsConstructor;
import com.fw.core.page.TableDataInfo;

/**
 * 规则配置Controller
 * 
 * @author yanwei
 * @date 2023-04-04
 */
@Api(tags = "sys_rule")
@RestController
@RequestMapping("/admin/sys_rule")
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class TbSysRuleController extends BaseController
{
    @Autowired
    private ITbSysRuleService tbSysRuleService;

    /**
     * 查询规则配置列表
     */
    @PreAuthorize("@ss.hasPermi('admin:sys_rule:list')")
    @GetMapping("/list")
    @ApiOperation("查询规则配置列表")
    public TableDataInfo list(TbSysRule tbSysRule)
    {
        startPage();
        List<TbSysRule> list = tbSysRuleService.selectTbSysRuleList(tbSysRule);
        return getDataTable(list);
    }

    /**
     * 导出规则配置列表
     */
    @PreAuthorize("@ss.hasPermi('admin:sys_rule:export')")
    @Log(title = "规则配置", businessType = BusinessType.EXPORT)
    @ApiOperation("导出规则配置列表")
    @GetMapping("/export")
    public AjaxResult export(TbSysRule tbSysRule)
    {
        List<TbSysRule> list = tbSysRuleService.selectTbSysRuleList(tbSysRule);
        ExcelUtil<TbSysRule> util = new ExcelUtil<TbSysRule>(TbSysRule.class);
        return util.exportExcel(list, "sys_rule");
    }

    /**
     * 获取规则配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('admin:sys_rule:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取规则配置详细信息")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(tbSysRuleService.selectTbSysRuleById(id));
    }

    /**
     * 新增规则配置
     */
    @PreAuthorize("@ss.hasPermi('admin:sys_rule:add')")
    @Log(title = "规则配置", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增规则配置")
    public AjaxResult add(@RequestBody TbSysRule tbSysRule)
    {
        return toAjax(tbSysRuleService.insertTbSysRule(tbSysRule));
    }

    /**
     * 修改规则配置
     */
    @PreAuthorize("@ss.hasPermi('admin:sys_rule:edit')")
    @Log(title = "规则配置", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改规则配置")
    public AjaxResult edit(@RequestBody TbSysRule tbSysRule)
    {
        return toAjax(tbSysRuleService.updateTbSysRule(tbSysRule));
    }

    /**
     * 删除规则配置
     */
    @PreAuthorize("@ss.hasPermi('admin:sys_rule:remove')")
    @Log(title = "规则配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除规则配置")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tbSysRuleService.deleteTbSysRuleByIds(ids));
    }
}
